package net.gxf.common.util;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;


/**
 * 
 * @author: maybe
 * 
 */
public class CheckNetUtil {
	private static final int DIE_TIME = 3000;// 单位毫秒,默认延时时间，超过表示不可用

	/**
	 * 网络检查，超过两秒表明网络不可用
	 * 
	 * @param urlsString
	 * @return
	 */
	public static boolean checkNet(String urlsString) {
		InputStream inputStream = null;
		try {
			URL url = new URL(urlsString);
			URLConnection conn = url.openConnection();
			conn.setReadTimeout(DIE_TIME);
			inputStream = conn.getInputStream();
		} catch (IOException e) {
			e.printStackTrace();
			return false;
		} finally {
			try {
				if (inputStream != null)
					inputStream.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return true;
	}

}
